package fun.zhufn.oldcomm.model.bo.customlist;

import fun.zhufn.oldcomm.model.bo.Old;
import fun.zhufn.oldcomm.model.bo.json.JsonList;
import fun.zhufn.oldcomm.model.bo.json.JsonMap;

public class OldList extends CustomList<Old>{
    @Override
    public JsonList toJsonList() {
        var ret = new JsonList();
        for (var v: data) {
            var mp = new JsonMap();
            mp.put("name", v.getName());
            mp.put("isMale", v.isMale());
            mp.put("birthday", v.getBirthday());
            mp.put("phone", v.getPhone());
            mp.put("server", v.getServer());
            mp.put("id", v.getId());
            ret.add(mp);
        }
        return ret;
    }

    @Override
    public void fromJsonList(JsonList d) {
        if (d == null) return;
        data.clear();
        for (Object o: d) {
            try {
                JsonMap v = (JsonMap) o;
                data.add(new Old(
                        (String)v.get("name"),
                        (Boolean)v.get("isMale"),
                        (String)v.get("birthday"),
                        (String)v.get("phone"),
                        (String)v.get("server"),
                        (int)v.get("id")
                ));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
